package com.cityos.android.mystudynestedscroll.ui.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.cityos.android.mystudynestedscroll.R
import com.cityos.android.mystudynestedscroll.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var mainBinding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mainBinding = ActivityMainBinding.inflate(layoutInflater).apply {
            setContentView(this.root)
        }
        mainBinding.appBarLayout.addOnOffsetChangedListener { appBarLayout , verticalOffset ->
            val toolBar = appBarLayout.findViewById<View>(R.id.toolbar)
            val t = (appBarLayout.bottom - toolBar.height) / (mainBinding.iv.height - toolBar.height.toFloat())
            mainBinding.iv.alpha = t
            mainBinding.toolbar.alpha = 1 - t
        }
        mainBinding.toolbar.alpha = 0.0f
    }
}